
<template>
  <div v-if="visible">
    <el-dialog :visible.sync="visible"
               title="导入"
               :modal="false"
               class="user-dialog add-or-updata"
               width="25%"
               :before-close="closeDialog"
               :close-on-click-modal="false"
               :close-on-press-escape="false">
      <el-form :model="dataForm"
               class="label-left-form"
               :element-loading-text="$t('loading')"
               ref="dataForm"
               label-position="left"
               label-width="100px">
        <el-form-item prop="rechargeType"
                      label="导入类型">
          <el-select v-model="dataForm.rechargeType"
                     placeholder="导入类型"
                     clearable>
            <el-option v-for="item in importOptions"
                       :key="item.value"
                       :label="item.label"
                       :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="导入表格">
          <file-upload reg=".(xlsx|xls)$"
                       ref="fileUpload"
                       accept=".xlsx,.xls"
                       title="上传表格"
                       :limit="1"
                       :paramData="{rechargeType:dataForm.rechargeType}"
                       action="/springbootApi/tb/companyRecharge/checkUserInfo"
                       @success="successImgLoad"
                       @remove="handleImgRemove" />
          <!-- <input id="upload"
                 type="file"
                 @change="importfxx()"
                 ref="uploadFile"
                 accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" /> -->
        </el-form-item>
      </el-form>
      <template slot="footer">
        <el-button @click="closeDialog()">{{ $t('cancel') }}</el-button>
      </template>
      <information-detection ref="informationDetectionDialog" @close='close' />

    </el-dialog>
  </div>
</template>

<script>
import minFormValidate from '@/mixins/form-validate'
import mixinViewModule from '@/mixins/view-module'
// import debounce from 'lodash/debounce'
import FileUpload from '@/components/file-upload/file-upload'
import InformationDetection from './information-detection.vue'
// import ImportContent from './import-content.vue'

// import Qs from 'qs'

export default {
  mixins: [mixinViewModule, minFormValidate],
  components: {
    FileUpload,
    InformationDetection
  },
  data () {
    return {
      mixinViewModuleOptions: {},
      visible: false,
      isRequest: false,
      dialogVisible: false,
      importOptions: [
        {
          label: '叠加充值',
          value: 0
        },
        {
          label: '重置充值',
          value: 1
        }
      ],
      dataForm: {
        rechargeType: 0
      }
    }
  },
  computed: {
  },
  methods: {
    successImgLoad (name, data) {
      console.log(name, data)
      if (data === '') {
        this.$message({
          type: 'success',
          message: '导入成功!'
        })
        this.closeDialog()
        this.$emit('callBack')
      } else {
        this.openDialog('informationDetectionDialog', data)
      }
    },
    close () {
      this.visible = false
      this.$emit('callBack')
    },
    handleImgRemove () {

    },
    closeDialog () {
      this.visible = false
    },
    init (data) {
      data = data || {}
      this.visible = true
      this.dataForm.id = data.id
    }
  }
}
</script>

<style lang="scss" scoped>
::deep .el-dialog__footer {
  text-align: right;
}
</style>
